<?php

$pack=$_GET['packname'];
$project=$_GET['project_name'];
$current_dir=$_GET['current_dir'];

if($current_dir==""){

}

else{
$current_dir=$current_dir."/";
}
if($pack=="")
{
echo "enter name of pack";
exit();
}


$c= "../projects/".$project.'/application/controller/'.$current_dir.$pack;
$m= "../projects/".$project.'/application/model/'.$current_dir.$pack;
$v= "../projects/".$project.'/application/view/'.$current_dir.$pack;
$e= "../projects/".$project.'/application/event_handler/'.$current_dir.$pack;

if(is_dir($c) || is_dir($m) || is_dir($v) || is_dir($e) 
        || is_file($c.".php") || is_file($m.".php") || is_file($v.".php") || is_file($e.".php")){
    
    echo "Folder or pack name conflict occured.";
    exit();
}


$c= "../projects/".$project.'/application/controller/'.$current_dir.$pack.".php";
$m= "../projects/".$project.'/application/model/'.$current_dir.$pack.".php";
$v= "../projects/".$project.'/application/view/'.$current_dir.$pack.".php";
$e= "../projects/".$project.'/application/event_handler/'.$current_dir.$pack.".php";

$cc=file_get_contents("../projects/".$project.'/system/helpers/defaults/default_controller.php');
$cc=str_replace('default_controller',$pack,$cc);
$cc=str_replace('base_dir',$current_dir,$cc);
$mc=file_get_contents("../projects/".$project.'/system/helpers/defaults/default_model.php');
$mc=str_replace('default_controller',$pack,$mc);
$vc=file_get_contents("../projects/".$project.'/system/helpers/defaults/default_view.php');
$vc=str_replace('default_controller',$pack,$vc);
$ec=file_get_contents("../projects/".$project.'/system/helpers/defaults/default_eventhandler.php');
$ec=str_replace('default_controller',$pack,$ec);
file_put_contents($c,$cc);
file_put_contents($m,$mc);
file_put_contents($v,$vc);
file_put_contents($e,$ec);

echo "Package was successfully Created!";
?>
